﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

using prototype123.models;
using prototype123.data_access;

namespace prototype123.controllers
{

    // MaintainAssignmentsController handles Adding/Deleting/Updating Course Information
    class MaintainAssignmentsController
    {

        // Function: AddAssignment
        // Adds an assignment to the db having <stuid>, <name>, <category>, <points_earned>, and <points_possble> as the data to go in the db
        // Preconditions: assumes that the above parameters passed from the UI is valid
        // Postconditions: the database is updated and an assignment is returned
        public Assignment AddAssignment(int stuid, string name, int category, int points_earned = 0, int points_possible = 0)
        {
            Assignment new_assmt = new Assignment(name, category, points_possible, points_earned);
            AssignmentDAO assmt_dao = new AssignmentDAO(Connector.Instance.Connection);
            int asmmt_id = assmt_dao.AddAssignment(new_assmt);
            new_assmt.AssignmentID = asmmt_id;
            Debug.WriteLine(DateTime.Now + ": User has succesfully added an Assignment - MaintainAssignmentsController");
            return new_assmt;
        }

        // Function: DeleteAssignment
        // Deletes an assignment from the database having <stuid> and <name> and returns the assignment deleted
        // Preconditions: assumes that the above parameters passed from the UI is valid
        // Postconditions: the database has lost one assignment and the deleted assignment is returned
        public void DeleteAssignment(int asmt_id)//Assignment assmt)
        {
            AssignmentDAO assmt_dao = new AssignmentDAO(Connector.Instance.Connection);
            assmt_dao.DeleteAssignment(asmt_id);
            Debug.WriteLine(DateTime.Now + ": User has succesfully deleted an Assignment - MaintainAssignmentsController");
        }

        // Function: UpdateAssignment
        // Handles updating the assignment <name> of <stuid> by either changing any of the fields.
        // Preconditions: assumes that the above parameters passed from the UI is valid
        // Postconditions: Updates an assignment in the db with new information, and returns it.
        public void UpdateAssignment(int old_asmt_id, Assignment new_asmt)
        {
            AssignmentDAO assmt_dao = new AssignmentDAO(Connector.Instance.Connection);
            assmt_dao.UpdateAssignment(old_asmt_id, new_asmt);
            Debug.WriteLine(DateTime.Now + ": User has succesfully updated an Assignment - MaintainAssignmentsController");
        }
    }
}
